package cn.fengshenghospital.controller;

import cn.fengshenghospital.entity.CmsMenu;
import cn.fengshenghospital.entity.User;
import cn.fengshenghospital.service.CmsMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;

//@RequestMapping("/cmsMenu")
@Controller
public class CmsMenuController {
    @Autowired
    private CmsMenuService cmsMenuService;

    @GetMapping("/cmsMenu")
    public String queryCmsMenu(Model model){
        try {
            List<CmsMenu> cmsMenuList = cmsMenuService.queryCmsMenu();
            model.addAttribute("cmsMenuList",cmsMenuList);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "main";
    }

    @GetMapping("/icons")
    public void quna(Model model){
//        Subject subject = SecurityUtils.getSubject();
//        User user = (User)subject.getPrincipal();
//        System.out.println(user.getUserName());

    }

    @GetMapping("/test")
    @ResponseBody
    public void updateCmsMenu(HttpSession session){
        User user = (User)session.getAttribute("user");
        System.out.println(user.getUserName());
//        System.out.println("++++++++++++++++++++++++++");
//        Subject subject = SecurityUtils.getSubject();
//        User user = (User)subject.getPrincipal();
//        System.out.println(user.getUserName());
    }

    @PostMapping("/cmsMenuTest")
    public void updateCmsMenu1(Integer id){
        System.out.println("PostMapping："+id);
    }
}
